{include file="admin@public/header"/}
<style>
.wrapper .disable,.wrapper .disable:hover{background:#ccc; color:#666; cursor:default;}
#endDate{ width:160px;}
.href-box{height: 28px;line-height: 28px;display: inline-block;}
.p{
  font-size:15px; padding-top: 5px;
}
</style>
</head>

<body>

<div class="wrapper">
  <div class="mod-search cf">
      <div class="fl">
          <ul class="ul-inline">
            <li>
              <label>日期:</label>
                <input type="date" id="endDate" name="endDate" class="ui-input " />
            </li>

            <li>
              <a class="ui-btn" id="accounts" onclick="add()">结账</a>
              <a class="ui-btn mrb" id="unaccounts">反结账</a>
            </li>
            
            <li class="href-box">
              <a href="https://club.kingdee.com/club/newclub/school/course?product_id=7&cid=1546#pid=5672" target="_blank" class="video-icon"></a>
              <span>结账与重算成本</span>
            </li></br>
            <li>
          <p class="p" id="pm" style="display:none;">系统启用时间为:<span style=" color: red;">2021-7-14</span>,系统还没有进行结账！</p>
          <p class="p" id="py" style="display:none;">结账日期不能小于系统启用日期：<span style=" color: red;">2021-7-14</span>，不能小于等于上次结账日期：<span style=" color: red;"id="time">2021-10-01！</span></br >结账日期之前的数据只能查询，不能修改。</p>
        </li>
          </ul>

      </div>

  </div>

  <div id="J_htmltip"></div>
    <br/>
    <div class="grid-wrap">
   <table id="grid">
     </table>
     <div id="page"></div>
   </div>
    </div>
</div>
<script type="text/javascript">
  document.getElementById('endDate').valueAsDate=new Date();//当前时间赋值
   $("#grid").jqGrid({
        url: '/system/check/index.html?ajax=100',
        datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
        height: '650px',//高度，表格高度。可为数值、百分比或'auto'
        //width: Public.setGrid().w,
        //height: Public.setGrid().h,
        colNames: ['结账日','操作日期','操作人员'],
        colModel: [
          { name: 'check_cdate',index:'check_cdate' ,width: 220},
          { name: 'check_time', index: 'check_time', width: 300 },
          { name: 'check_username', index: 'check_username', width: 200},
        ],
        rowNum: 10,
        rowList: [10, 50, 100],
        sortname: 'id',
        sortorder: "desc",
        pagerpos: "left",//分页位置

        pgbuttons: true,//翻页按钮
        pagination: true,
        altRows: !0,
        gridview: !0,
        shrinkToFit: !1,
        cellLayout: 8,
        autowidth: !0,
        pager: "#page",
        viewrecords: !0,
        cmTemplate: {
          sortable: !1,
          title: !1
        },
        loadError: function (t, e, i) {
          parent.Public.tips({
            type: 1,
            content: "操作失败了哦，请检查您的网络链接！"
          })
        },
        //加载完成后输出的内容
        gridComplete:function(){
        var records = $("#grid").jqGrid('getGridParam', 'records'); //获取数据总条数
         if (records!== null && records>0) {
            var ids = $('#grid').getDataIDs();//返回数据表的ID数组
            var rowData = $("#grid").getRowData(ids[0]);
            var res = $("#grid").jqGrid('getRowData', rowData);
            var time= res[0].check_cdate;
            $("#time").text(time+'!');
            $("#py").css('display','block');
            $("#pm").css('display','none');
          return false;
         }else{
            $("#pm").css('display','block');
            $("#py").css('display','none');
          return false;
         }
      }
      });
      function add(){
        var endDate=$("#endDate").val();
        var add='0';
        layer.confirm('确定要结账吗？',function (){
           $.ajax({
            type:'post',
            url:'save',
            datatype:'json',
            data:{
              'add':add,
              'endDate':endDate,
            },
              success:function(data){
                if (data.code==1) {
                  layer.msg(data.msg,{icon:1,time:1000});
                  $("#grid").jqGrid('setGridParam', {
                  datatype: 'json',
                  postData: { 'ajax': '100'}, //发送数据 
                  page: 1
                  }).trigger("reloadGrid"); //重新载入 
                }else{
                  var index=layer.msg(data.msg,{icon:5});
                  layer.style(index,{
                    width:'405px'
                  });
                }
              },
              error:function(da){
                layer.msg('请求失败',{icon:2,time:1000});
              },
           })
         });
      };
      $("#unaccounts").click(function(){
        var add='1';
        $.ajax({
          type:'post',
          url:'save',
          datatype:'json',
          data:{
            'add':add,
          },
            success:function(data){
              if (data.code==1) {
                    layer.msg(data.msg,{icon:1,time:1000});
                      $("#grid").jqGrid('setGridParam', {
                      datatype: 'json',
                      postData: { 'ajax': '100'}, //发送数据 
                      page: 1
                      }).trigger("reloadGrid"); //重新载入 
                  }else{
                    layer.msg(data.msg,{icon:2,time:1000});
                  }
                },
            error:function(da){
              layer.msg('请求失败',{icon:2,time:1000});
            },
        })
      })
</script>
{include file="admin@public/footer"/}